﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using CustomsSystem.BLL;
using CustomsSystem.Model;

namespace WEB.T_bill
{
    public partial class coststatistics : System.Web.UI.Page
    {
        public DataSet ds;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //数据绑定
                SheetInfoManage sheetManage = new SheetInfoManage();
                ds = sheetManage.GetView("");
                gvSheetInfo.DataSource = ds;
                gvSheetInfo.DataBind();
                Session["高级搜索"] = "0";
                tbbegDate.Attributes.Add("onClick", "new WdatePicker()");
                tbendDate.Attributes.Add("onClick", "new WdatePicker()");
            }
            if (Session["高级搜索"] == "1")
            { 
                tbbegDate.Attributes .Add("onClick", "new WdatePicker()");
                tbendDate.Attributes.Add("onClick", "new WdatePicker()");
            }
        }

        protected void gvSheetInfo_SelectedIndexChanging(object sender,GridViewSelectEventArgs e)
        {
            Session["sheetID"] = gvSheetInfo.Rows[e.NewSelectedIndex].Cells[0].Text.ToString ();
            Session["CustomerName"] = gvSheetInfo.Rows[e.NewSelectedIndex].Cells[3].Text.ToString ();
            Response.Redirect("receivables.aspx");
            //Response.Write("<script>history.go(-2);</script>");
        }


        protected void btnQuery_Click(object sender, EventArgs e)
        {

            BillManage bll = new BillManage();
            string a = tbQuery.Text.Trim();
            DataSet ds = new DataSet();
            ds = bll.GetList(a);


            gvSheetInfo.DataSource = ds;
            gvSheetInfo.DataBind();
        }

        protected void btnHserch_Click(object sender, EventArgs e)
        {
            Session["高级搜索"] = "1";
        }

        /// <summary>
        /// 获取人员表
        /// </summary>
        /// <returns></returns>
        public DataTable GetEmpNum()
        {
            CustomsSystem.BLL.UserManage UserManage = new UserManage();
            DataSet ds = UserManage.GetAllList();
            DataTable dt = ds.Tables[0];
            return dt;

        }

        [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public static string[] GetCustomersName(string prefixText, int count)
        {
            CustomerManage cusManage = new CustomerManage();
            List<string> strArray = new List<string>();
            //string[] strArray = { "中国石油公司","中顺洁柔","中山技术",
            //"捷达捷达捷达达","时代复分","幅度为爱"};
            List<Customer> cusList = cusManage.GetModelList("");
            foreach (Customer aCus in cusList)
            {
                strArray.Add(aCus.CustomerName);
            }
            return (from m in strArray
                    where m.Contains(prefixText)
                    select m).Take(count).ToArray();
        }

    }
}